package com.lzw.cpvideoplayer.mvp.model;


import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.widget.Toast;

import com.lzw.cpvideoplayer.data.HeadData;
import com.lzw.cpvideoplayer.data.cHeadData;

import androidx.annotation.NonNull;

public class BaseModel implements IModel{
    private onLoadModel onLoadModel;
    private Context mContext;
    private Handler handler = new Handler(){
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            if(msg.what == 1){
                onLoadModel.onLoadData((HeadData) msg.obj);
            }else if(msg.what == 2) {
                onLoadModel.onLoadData((cHeadData) msg.obj);
            }else if(msg.what == 3){
                Toast.makeText(mContext,"请求失败:(",Toast.LENGTH_SHORT).show();
            }
        }
    };

    @Override
    public void setOnLoadModel(Context context, String url,onLoadModel onLoadModel,int what) {
        mContext = context;
        this.onLoadModel = onLoadModel;
        if(what == 1){
            LoadHttpData.getInstance().LoadVideoData(url,handler,context,what);
        }else {
            LoadHttpData.getInstance().LoadVideoData(url,handler,context,what);
        }


    }
}
